﻿using Microsoft.AspNetCore.SignalR;
using PLCS.Domain.Stations;
using Volo.Abp.AspNetCore.SignalR;

namespace PLCS.Application.StationApp.Hubs
{
    public class StationHub : AbpHub
    {
        private readonly IStationRepository _repository;

        public StationHub(IStationRepository repository)
        {
            _repository = repository;
        }

        public override Task OnConnectedAsync()
        {
            return base.OnConnectedAsync();
        }

        public async Task InitalStatus(string sname)
        {
            await Task.Run(async () =>
             {
                 Station station = await _repository.FindAsync(x => x.StaName == sname);
                 if (station != null)
                 {
                     await Clients.Caller.SendAsync("ChangeStatus", sname, station.HaveStatus);
                 }
             });
        }
    }
}